/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public ListNode deleteNode(ListNode head, int val) {
        ListNode prev = head;
        if(head.val == val){
           return head.next;
        }
        while(prev.next != null){
            if(prev.next.val == val){
                ListNode cur = prev.next;
                prev.next = cur.next;
            }else{
                prev = prev.next;
            }
        }
        return head;
    }
}